package handler

import (
	"design-base/modle"
	"github.com/gin-gonic/gin"
	"strconv"
)

func Add(c *gin.Context) {

	name := c.PostForm("name")
	price, _ := strconv.Atoi(c.PostForm("price"))

	if name == "" || price == 0 {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不为空",
		})
		return
	}

	var data = modle.Shop{
		Name:  name,
		Price: price,
	}

	err := modle.DB.Create(&data).Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "添加失败",
		})
		return
	}

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": data,
	})
	return

}

func Detail(c *gin.Context) {

}
